<?php

namespace App\Jobs;


use App\Libraries\Easemob\Easemob;
use App\Libraries\Tools\Msg;
use App\Models\HongBao\HongBao;
use App\Models\Msg\MsgSystem;
use Illuminate\Support\Facades\Log;
use JMessage\IM\Friend;
use JMessage\JMessage;

class AddIMFriends extends Job
{


    private $user_id;


    public function __construct($user_id)
    {
        $this->user_id = $user_id;
    }

    /**
     * Execute the job.
     *
     * @return bool
     */
    public function handle()
    {
        //创建环信账号
//        $data = Easemob::singleton()->createUser($this->user_id, md5($this->user_id));
//        Easemob::singleton()->addFriend(3, $this->user_id);
//        Easemob::singleton()->addFriend(4, $this->user_id);
//        Easemob::singleton()->addFriend(5, $this->user_id);
//        Easemob::singleton()->addFriend(6, $this->user_id);
//        Easemob::singleton()->addFriend(7, $this->user_id);
//        Easemob::singleton()->addFriend(8, $this->user_id);
//        if(!empty($data['error'])){
//            return false;
//        }
        $client = new JMessage(env('JMSG_APPKEY'), env('JMSG_SECRET'));
        $friend = new Friend($client);
        $friend->add("beboy_".$this->user_id, [
            'beboy_3',
            'beboy_4',
            'beboy_5',
            'beboy_6',
            'beboy_7',
        ]);
        return true;
    }
}
